package com.alex.algorithm.easy;

import java.util.*;

public class IntersectionOfTwoArray {

    public static void main(String[] args) {
        intersectionOfTwoArray(new int[]{1,2,3,5,6,9},new int[]{0,2,3,4,0,9}).stream().forEach(System.out::println);
    }

    public static List intersectionOfTwoArray(int[] arrayA, int[] arrayB) {
        Set<Integer> set = new HashSet<>();
        Arrays.stream(arrayA).forEach(i -> set.add(i));
        List<Integer> res = new ArrayList<>();
        Arrays.stream(arrayB).forEach(i -> {
            if (set.contains(i)) {
                res.add(i);
            }
        });
        return res;
    }
}
